<template>
  <div class="container">
    <div class="table">
      <el-table
        :data="tableData"
        style="width: 80%; height: 98%;"
        v-loading="loading"
        fit
        height="750"
      >
        <el-table-column prop="Id" label="序号" width="70"> </el-table-column>
        <el-table-column prop="f013" label="设备品种"></el-table-column>
        <el-table-column prop="f037" label="企业编号"></el-table-column>
        <el-table-column prop="f015" label="规格型号"></el-table-column>
        <el-table-column prop="f032" label="使用单位"></el-table-column>
        <el-table-column prop="checkLastDate" label="上次检验日期"></el-table-column>
        <el-table-column prop="checkNextDate" label="下次检验日期"></el-table-column>
        <el-table-column prop="inform" label="检验告知"></el-table-column>
        <el-table-column prop="checkPlan" label="检验计划"></el-table-column>
      </el-table>
    </div>
    <div class="page">
      <el-pagination
        background
        @size-change="pageSizeChange"
        @current-change="pageChange"
        :current-page="currentPage"
        :page-sizes="[15, 30, 50, 80]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { req } from "@/api/base/BaseApi";
export default {
  created() {
    this.searchList();
  },
  data() {
    return {
      tableData: [], // 表格数据
      total: 0, // 表格数据总项数
      loading: false, // 表格是否在加载
      pageSize: 30, // 默认一页15项数据
      currentPage: 1,
    };
  },
  props: {
    checkUnit: String,
  },
  methods: {
    // 获取数据
    async searchList() {
      const { data } = await req("/lifting-service/info/checkinfo", "GET", {
        inspection: this.checkUnit,
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      });
      const { list, total } = data;
      this.generateIds(list);
      for(const item of list){
        if(+item.inform<0){
          item.inform='已安排'
        }else{
          item.inform=""+item.inform+"天"
        }
        item.checkPlan='未安排' 
      }
      this.tableData = list;
      this.total = total;
    },
    // 页面大小改变
    async pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.currentPage = 1;
      // 获取数据
      this.searchList();
    },
    // 页数改变
    async pageChange(page) {
      this.currentPage = page;
      // 获取数据
      this.searchList();
    },
    getRowClass({ row, column, rowIndex, columnIndex }) {
      console.log("调用行样式");
      return {
        background: "#06134A",
        color: "#72C22D",
      };
    },
    // 根据页面生成数据的ID
    generateIds(list) {
      for (const index in list) {
        list[index].Id = +index + 1 + this.pageSize * (this.currentPage - 1);
      }
    },
  },
};
</script>
<style lang="less" scoped>
.container {
  display: flex;
  flex-direction: column;
}
</style>